function CF = CFSVJEJ2(Phi,Price,Rate,DividendYield,Times,V0,ThetaV,Kappa,SigmaV,RhoSV,JumpFreq,mj,JumpVol,prob,mlow,slow,shigh,Numeraire)
%% ---------------description---------------------------------------------
%characteristic function of the SVJEJ2 model
%Price = current stock price
%Rate = interest rate
%DividendYield = dividend yield
%Times = time-to-maturity
%V0 = spot variance
%ThetaV = long-run variance
%Kappa = mean reversion
%SigmaV = volatility of volatility
%RhoSV = correlation coefficient between stock price and volatility
%JumpFreq = jump frequency
%mj = the mean jump size
%JumpVol = the jump size volatility
%prob = the probability of an downside jump
%mlow = the mean of the downside jump
%slow = the volatility of the upside jump
%shigh = the volatility of the upside jump
%Numeraire = 0 for the ordinary characteristic function
%          = 1 for the variant of characteristic function used in option
%          pricing
%% -----------------------------------------------------------------------
qprob=1-prob;%the probability of an upside jump
%Note: mhigh is derived from the other parameters so that the price is a martingale at EAD
mhigh=log((1-prob.*exp(mlow+0.5.*slow.^2))./qprob) - 0.5.*shigh.^2;
x=log(Price);
Phi = Phi(:);
if Numeraire == 1
    u = 0.5;
    b = Kappa-RhoSV.*SigmaV;
else
    u = -0.5;
    b = Kappa;
end
    
d = sqrt((b-RhoSV.*SigmaV.*1i.*Phi).^2 - SigmaV.^2.*(2.*u.*1i.*Phi-Phi.^2));
bRhSigmaPd = b - RhoSV.*SigmaV.*1i.*Phi + d;
bRhSigmaMd = b - RhoSV.*SigmaV.*1i.*Phi - d;
gtrap = bRhSigmaMd./bRhSigmaPd;
expMdTime = exp(-d.*Times);
C = (Rate - DividendYield).*1i.*Phi.*Times + Kappa.*ThetaV./SigmaV.^2.* ...
        (bRhSigmaMd.*Times - 2.*log((1-gtrap.*expMdTime)./(1-gtrap)));
D = bRhSigmaMd./SigmaV.^2.*(1-expMdTime)./(1-gtrap.*expMdTime);
fheston = exp(C + D.*V0 + 1i.*Phi.*x);
MeanJ = exp(mj + 0.5.*JumpVol.^2)-1;
if Numeraire == 1
    fjump = exp(JumpFreq.*Times.*((1+MeanJ).*((1+MeanJ).^(1i.*Phi).* ...
        exp(JumpVol.^2.*(0.5.*1i.*Phi-0.5.*Phi.^2))-1) - MeanJ.*1i.*Phi));
else   
    fjump = exp(JumpFreq.*Times.*(((1+MeanJ).^(1i.*Phi).* ...
        exp(JumpVol.^2.*(-0.5.*1i.*Phi-0.5.*Phi.^2))-1) - MeanJ.*1i.*Phi));
end
fbates = fheston.*fjump;
if Numeraire ==1
    fead = prob.*exp((1i.*Phi+1).*mlow + 0.5.*(1i.*Phi+1).^2.*slow.^2) + qprob.*exp((1i.*Phi+1).*mhigh + 0.5.*(1i.*Phi+1).^2.*shigh.^2);
else
    fead = prob.*exp(1i.*Phi.*mlow + 0.5.*(1i.*Phi).^2.*slow.^2) + qprob.*exp(1i.*Phi.*mhigh + 0.5.*(1i.*Phi).^2.*shigh.^2);
end
CF = fbates.*fead;
end

